package com.pingao.mp.modular.sys.controller;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class HttpController implements ErrorController {

    private static final String ERROR_PATH = "/error";
    @GetMapping(value=ERROR_PATH)
    public String handleError(HttpServletRequest request){
        if(request.getRequestURL().toString().contains("/api")){
            return "api/sys/http/404";
        }
        return "sys/http/404";
    }


    @GetMapping("/sys/error/500")
    public String handle500Exception(String message, ModelMap map){
        map.addAttribute("message",message);
        return "sys/http/500";
    }
    @Override
    public String getErrorPath() {
        return ERROR_PATH;
    }
}
